<template>
	<view class="container">
		<TopBtn :title="'团队详情'"></TopBtn>
		<view class="listBox">
			<view class="list" v-for="n in list" :key="n.id">
				<view class="">
					<view class="title flex-center">
						<image src="@/static/my/tx.png" mode=""></image>
						<view class="">
							<view class="name">
								{{n.doctorName}} <text>{{n.titleName}}</text> <text>{{n.departName}}</text>
							</view>
							<view class="typeBox">
								<text v-if="n.levelName">{{n.levelName}}</text> {{n.hospitalName}}
							</view>
						</view>
					</view>
					<view class="text rowShow_2">
						<text>擅长：</text> {{n.proficient}}
					</view>
					<view class="btmBox flex-sp-center">
						<uni-dateformat :date="n.createTime" format="yyyy-MM-dd hh:mm"></uni-dateformat>
						<view class="del flex-center" @click="del(n.id)" v-if="isMy">
							<image src="@/static/my/del.png" mode=""></image> 删除
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="btnBox" v-if="isMy">
			<view class="close flex-center-center" @click="dissolveTeam()">
				解散团队
			</view>
			<view class="addbtn flex-center-center" @click="goAdd()">
				邀请成员
			</view>
		</view>

		<view class="kong">

		</view>
	</view>
</template>

<script>
	import {
		getTeamManagePage,
		deleteTeamManage,
		dissolveTeam
	} from '@/api/user'
	export default {
		data() {
			return {
				act: "1",
				list: [],
				request: {
					pageNo: 1,
					pageSize: 10,
				},
				maxNum: "",
				userId: uni.getStorageSync('userId'),
				isMy: false

			};
		},
		onShow() {
			let that = this
			uni.$once('show', function(data) {
				if (data) {
					that.request.pageNo = 1
					that.list = []
					that.getTeamManagePage()
				}
			})
		},
		onUnload() {
			uni.$off()
		},
		onLoad(e) {
			if (this.userId == e.id) {
				this.isMy = true
			}
			this.request.doctorId = e.id
			this.list = []
			this.getTeamManagePage()
		},
		onReachBottom() {
			if (this.maxNum <= this.request.pageNo) return
			this.request.pageNo = this.request.pageNo + 1
			this.getTeamManagePage()
		},
		methods: {
			dissolveTeam(id) {
				if (!this.isMy) {
					return
				}
				var _this = this
				uni.showModal({
					title: '提示',
					content: '是否解散团队',
					success: function(res) {
						if (res.confirm) {
							dissolveTeam().then(res => {
								_this.list = []
								_this.request.pageNo = 1
								_this.getTeamManagePage()
								uni.showToast({
									title: '解散成功',
									icon: 'none',
									duration: 1000,
								})
								uni.navigateBack({
									delta: 1, //返回层数，2则上上页
								})
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					},
				})
			},
			del(id) {
				var _this = this
				uni.showModal({
					title: '提示',
					content: '是否确认删除',
					success: function(res) {
						if (res.confirm) {
							deleteTeamManage(id).then(res => {
								_this.list = []
								_this.request.pageNo = 1
								_this.getTeamManagePage()
								uni.showToast({
									title: '删除成功',
									icon: 'none',
									duration: 1000,
								})
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}

					},
				})
			},
			getTeamManagePage() {
				getTeamManagePage(this.request).then(res => {
					this.list.push(...res.data.list)
					let num = res.data.total / this.request.pageSize
					if (num.toString().includes('.')) {
						num = Math.ceil(num)
					}
					this.maxNum = num
				})
			},
			goAdd() {
				uni.navigateTo({
					url: `/pages/ConsultationRoom/SelectPersonnel/SelectPersonnel?type=team`,
				})
			},
			goinfo(id) {
				if (id) {
					uni.navigateTo({
						url: `/pages/prescription/details/details?id=${id}`,
					})
				}
			},
		}
	}
</script>

<style lang="less" scoped>
	.btnBox {
		position: fixed;
		display: flex;
		width: 100%;
		justify-content: space-between;
		font-weight: 500;
		font-size: 26rpx;
		bottom: 20rpx;
		box-sizing: border-box;
		padding: 0 50rpx;


		.close {
			width: 259rpx;
			height: 95rpx;
			color: #999999;
			background: #e7e7e7;
			border-radius: 48rpx;
		}

		.addbtn {
			width: 351rpx;
			height: 95rpx;
			background: #3E6EFE;
			border-radius: 48rpx;
			color: #FFFFFF;
		}
	}

	.listBox {
		margin-top: 43rpx;
		padding: 0 30rpx;

		.list {
			width: 690rpx;
			min-height: 182rpx;
			background: #FFFFFF;
			border-radius: 30rpx;
			padding: 20rpx;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			justify-content: space-around;
			margin-bottom: 30rpx;

			&>view {
				flex: 1;
			}

			.btmBox {
				padding-top: 10rpx;
				margin-top: 15rpx;
				font-weight: 500;
				font-size: 26rpx;
				color: #999999;
				border-top: 1rpx solid #eee;

				.del {
					color: #3B6CFE;
				}

				image {
					width: 31rpx;
					height: 29rpx;
					margin-right: 10rpx;
				}
			}

			.title {
				.name {
					font-weight: bold;
					font-size: 32rpx;
					color: #333333;

					text {
						font-weight: 500;
						font-size: 24rpx;
						color: #666666;
						margin-left: 19rpx;
					}
				}

				image {
					width: 90rpx;
					height: 90rpx;
					margin-right: 30rpx;
				}
			}

			.text {
				font-weight: 500;
				font-size: 26rpx;
				color: #333333;
				margin-top: 30rpx;
				// padding-bottom: 30rpx;

				text {
					color: #999;
				}
			}

			.typeBox {
				margin-top: 15rpx;
				font-weight: 500;
				font-size: 26rpx;
				color: #666666;

				text {
					display: inline-block;
					width: 63rpx;
					height: 33rpx;
					background: #DEF7ED;
					border-radius: 10rpx;
					font-weight: 500;
					font-size: 22rpx;
					color: #23CC88;
					text-align: center;
					line-height: 33rpx;
					margin-right: 10rpx;
				}

			}


		}
	}
</style>